/*
 * @(#)TestImplementationTester.java 	1.0 2010/07/12
 * 
 * Copyright 2010 David Croft and guyven
 */
package com.iawg.attrition.test;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.iawg.attrition.engine.messaging.BasicMessageHandler;
import com.iawg.attrition.engine.messaging.BasicMessagePrefix;
import com.iawg.attrition.game.Action;
import com.iawg.attrition.game.GameCommand;
import com.iawg.attrition.game.GameEngine;
import com.iawg.attrition.game.gui.SimpleCanvas;
import com.iawg.attrition.game.map.Board;
import com.iawg.attrition.game.map.Map;
import com.iawg.attrition.game.map.Position;
import com.iawg.attrition.game.map.Tile;
import com.iawg.attrition.game.units.Building;
import com.iawg.attrition.game.units.Unit;


/**
 * This class is meant to test unit interaction.
 * 
 * @author William David Croft Jr.
 * @author guyven
 * @version 1.0 2010/07/12
 */
public class TextImplementationTester {

	/**
	 * The method will create a new map for our Actors to act in.
	 * 
	 * @return The created map.
	 */
	private static Map createMap(){
		Map currentMap = new Map();
		currentMap.setMapAuthor("XaviorArrokoth");
		currentMap.setMapName("Angel Grove");
		currentMap.setMapDescription("The area around Ernie's Juice Bar and Recreation Center.");
		currentMap.setMaximumNumberOfPlayers(2);
		currentMap.setBoard(createBoard());
		return currentMap;
	}

	/**
	 * The method will create a new board for our Actors to act on.
	 * 
	 * @return The created Board.
	 */
	private static Board createBoard(){
		Tile[][] tileMatrix = new Tile[10][10];
		for(int columnIndex = 0; columnIndex < 10; columnIndex++){
			for(int rowIndex = 0; rowIndex < 10; rowIndex++){
				tileMatrix[columnIndex][rowIndex] = new Tile();
			}
		}
		Board board = new Board(tileMatrix);
		return board;
	}

	public static void main(String[] args){
		System.out.println("Start");
		Map currentMap = createMap();
		Unit mover = new Unit();
		Building immovableBuilding = new Building();
		currentMap.getBoard();
		mover.setName("Ernie");
		mover.setPosition(new Position(0, 0));
		immovableBuilding.setName("Ernie's Juice Bar and Recreation Center");
		immovableBuilding.setPosition(new Position(5, 5));
	
		BasicMessageHandler mh = GameEngine.ENGINE.getMessageHandler();

		try {
			//loads up the resources
			mh.inform(BasicMessagePrefix.RESOURCE_LOAD, currentMap);
			mh.inform(BasicMessagePrefix.RESOURCE_LOAD, mover);
			mh.inform(BasicMessagePrefix.RESOURCE_LOAD, immovableBuilding);
			
			//this sends the engine a notice to move the mover guy to position 8.6, 8.6
			mh.inform(BasicMessagePrefix.COMMAND, new GameCommand(mover, Action.MOVE, new Position(8.6f, 8.6f)));
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		// before you run this, make sure to set up the following in
		// the launch configuration (Arguments->VM Arguments) for the correct SWT lib. path
		// the following is a windows example,
		// -Djava.library.path="installation_directory\plugins\org.eclipse.swt.win32_3.0.1\os\win32\x86"
		Display display = Display.getDefault();
		Shell shell = new SimpleCanvas().getShell();
		shell.open();
	
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
		System.exit(0);
	}
}